package com.cnap.db.handler;

import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.TypeHandler;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class BoolHandler implements TypeHandler<Boolean> {

    @Override
    public void setParameter(PreparedStatement preparedStatement, int i, Boolean aBoolean, JdbcType jdbcType) throws SQLException {
        preparedStatement.setString(i, aBoolean.toString());
    }

    @Override
    public Boolean getResult(ResultSet resultSet, String s) throws SQLException {
        String str = resultSet.getString(s);
        return Boolean.parseBoolean(str);
    }

    @Override
    public Boolean getResult(ResultSet resultSet, int i) throws SQLException {
        String str = resultSet.getString(i);
        return Boolean.parseBoolean(str);
    }

    @Override
    public Boolean getResult(CallableStatement callableStatement, int i) throws SQLException {
        String str = callableStatement.getString(i);
        return Boolean.parseBoolean(str);
    }
}
